package models

import (
	"time"
)

type Comment struct {
	ID            uint      `gorm:"primarykey" json:"id"`
	Content       string    `gorm:"type:text;not null" json:"content"`
	CommentatorID uint      `json:"commentatorId"`
	ResourceType  string    `gorm:"not null" json:"resourceType"` // 'question' 或 'answer'
	ResourceID    uint      `gorm:"not null" json:"resourceId"`
	RootCommentID *uint     `json:"rootCommentId,omitempty"` // 二级评论的根评论ID
	ReplyToID     *uint     `json:"replyToId,omitempty"`     // 回复的评论ID
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`

	// 关联
	Commentator User       `gorm:"foreignKey:CommentatorID" json:"commentator,omitempty"`
	RootComment *Comment   `gorm:"foreignKey:RootCommentID" json:"rootComment,omitempty"`
	ReplyTo     *Comment   `gorm:"foreignKey:ReplyToID" json:"replyTo,omitempty"`
	Replies     []*Comment `gorm:"foreignKey:RootCommentID" json:"replies,omitempty"`
}
